import { Handle, useNodeConnections, useNodesData } from "@xyflow/react";

/**
 *
 * @param {*} param0 { data: 源数据 } 依赖上一个句柄的data
 * @returns
 */
function Log({ data }) {
  // 当前节点 边缘
  const connections = useNodeConnections({ handleType: "target" });

  //根据边缘 查找 上个Node数据
  const nodeData = useNodesData(connections?.[0].source); // [0]
  const color = nodeData.data
    ? nodeData.data[connections?.[0].sourceHandle]
    : null;

  return (
    <div
      className="log-node"
      style={{
        background: color ? `rgb(${color.r}, ${color.g}, ${color.b})` : "white",
        color: color ? data.fontColor : "black",
      }}
    >
      {color ? data.label : "Do nothing"}
      <Handle type="target" position="left" />
    </div>
  );
}

export default Log;
